import{C as e,D as t,T as n,a as r,c as i,d as a,gt as o,l as s,n as c,r as l,t as u}from"./B603vO-13smUKN.js";import{t as d}from"./CpAZygWZ2u2mWR.js";function f(e){return e.reduce((e,t)=>Math.min(e,t.sort||0),0)-1-o()}function p(e){return e.reduce((e,t)=>Math.max(e,t.sort||0),0)+1+o()}function m(e,t){e??=(t??0)-1,t??=(e??0)+1;let n=t-e;return e+n/2+n*.01*(o()-.5)}function h(e,t,n){let r=n.length,i=e<t;if(r<=0||e>=r-1)return p(n);if(e<=0)return f(n);n=g([...n]);let a=i?-1:0,s=n[e+a].sort||0,c=(n[e+a+1].sort||0)-s;return c===0?i?f(n):p(n):s+c/2+c*.01*(o()-.5)}function g(e){return[...e].sort((e,t)=>(e.sort||0)-(t.sort||0))}var _={between(e,t){if(e==null&&t==null)return o();if(e==null)return f([{sort:t}]);if(t==null)return p([{sort:e}]);let n=t-e;return n===0?e+1+o():e+n/2+n*.01*(o()-.5)},compare(e,t){return e-t}},v={between(e,t){return d(e,t,{jitter:4})},compare(e,t){return e<t?-1:+(e>t)}};function y(e,t,n){if(!e)return[];let r=[];for(let n of Object.keys(e)){let i=e[n];i!=null&&r.push({key:n,sort:t(i)})}return r.sort((e,t)=>e.sort==null&&t.sort==null?0:e.sort==null?-1:t.sort==null?1:n.compare(e.sort,t.sort)),r}function b(e,t){return[t>0?e[t-1]?.sort??null:null,t<e.length?e[t]?.sort??null:null]}function x(e){let t=e=>e;return{keys(n){return y(n,t,e).map(e=>e.key)},entries(n){return y(n,t,e).map(e=>({key:e.key,value:n[e.key]}))},add(n,r,i){let a={...n};if(r in a)return a;let o=y(n,t,e),[s,c]=b(o,i==null?o.length:Math.max(0,Math.min(i,o.length)));return a[r]=e.between(s,c),a},remove(e,t){if(!e||!(t in e))return{...e};let n={...e};return delete n[t],n},move(n,r,i){if(!n||!(r in n))return{...n};let a=y(n,t,e),[o,s]=b(a.filter(e=>e.key!==r),Math.max(0,Math.min(i,a.length-1)));return{...n,[r]:e.between(o,s)}}}}function S(e,t={}){let n=t.prop??`sort`,r=e=>e?.[n];return{keys(t){return y(t,r,e).map(e=>e.key)},items(t){return y(t,r,e).map(e=>({key:e.key,item:t[e.key]}))},add(t,i,a,o){let s={...t};if(i in s)return s;let c=y(t,r,e),[l,u]=b(c,o==null?c.length:Math.max(0,Math.min(o,c.length)));return s[i]={...a,[n]:e.between(l,u)},s},remove(e,t){if(!e||!(t in e))return{...e};let n={...e};return delete n[t],n},move(t,i,a){if(!t||!(i in t))return{...t};let o=y(t,r,e),[s,c]=b(o.filter(e=>e.key!==i),Math.max(0,Math.min(a,o.length-1)));return{...t,[i]:{...t[i],[n]:e.between(s,c)}}}}}var C=x(_),w=x(v);S(_),S(v);function T(){return e()===`test`?n(`test`):t()}function E(e){let t=!!(e&&(e.accept?.length||e.maxBytes!=null));return a().meta({asset:!t||e})}var D=i({_id:a().default(T).meta({swiftName:`uid`,swiftGetter:`uid!`}),_type:a().meta({swiftName:`type`}).describe("Type of the object, like `doc`, `category`, `contact`, `doctype`, `settings`, `tag` or `local`. Also defined as literal in each derived schema."),_deleted:l().optional().meta({swiftName:`deleted_`})});function O(e){return r().meta({ui:{kind:`days`,format:e?.format??`yyyymmdd`}})}function k(e){return e?Object.keys(e).filter(t=>e[t]===!0):[]}function A(e){let t={};for(let n of e??[])t[n]=!0;return t}function j(e){return a().meta({ui:{kind:`reference`,...e?.to?{to:e.to}:{},...e?.label?{label:e.label}:{}}})}function M(e){return s(l()).meta({ui:{kind:`set`,...e?.to?{to:e.to}:{},...e?.of?{of:e.of}:{},...e?.label?{label:e.label}:{}}})}var N=a();i({wid:a(),workspaceType:a(),role:a(),createdAt:r(),mode:N.optional()});var P=i({algorithm:a(),kdf:a(),kdfHash:a(),kdfIterations:r(),salt:a(),verify:a()});i({apiVersion:r(),workspaceId:a(),workspaceType:a(),createDate:r(),createClientId:a().optional(),mode:N.optional(),encryption:P.optional(),schemaVersion:r().optional()});var F=i({s:r(),c:a(),t:r(),v:r(),p:a().optional(),did:a().optional(),app:a().optional(),b:r().optional()}),I=i({cid:a(),idx:r()}),L=s(r());i({workspaceId:a().optional()}),i({workspaceId:a().optional(),encryption:P.optional()}),i({records:c(u()),app:a().optional(),b:r().optional()}),i({schemaVersion:r(),records:c(u()),app:a().optional(),b:r().optional()}),i({schemaVersion:r(),from:a(),select:c(a()).optional(),where:u().optional(),sort:u().optional(),limit:r().optional(),offset:r().optional()}),i({schemaVersion:r(),rows:c(u()),partial:l()}),i({transactions:c(i({ref:I,header:F,records:c(u())})),cursor:L}),i({ref:I,header:F});export{k as a,C as c,p as d,h as f,M as i,w as l,f as m,A as n,E as o,g as p,j as r,D as s,O as t,m as u};